object NestedFunction {
  def main(args: Array[String]): Unit = {
    val l1 = List(100,200,300)
    println(l1.head)
    println(l1.tail)
    println(filter(List(1,2,3,4,5,6,7),4))
  }

  def filter(xs:List[Int],threshold:Int):List[Int] = {
    def process(ys:List[Int]):List[Int] = {
      if (ys.isEmpty) ys
      else if (ys.head < threshold) {
        ys.head :: process(ys.tail)
      }
      else
        process(ys.tail)
    }
    process(xs)
  }

}
